/**
 * 
 */
package javas.system;

import java.net.URL;

import javas.system.classloader.ExampleObject;
import javas.system.classloader.ExampleObjectImpl;

/**
 * @author lionbule
 */
public class TestClassloader {

    /**
     * @param args
     * @throws Exception
     * @throws
     */
    public static void main(String[] args) throws Exception {
        ExampleObject testObject = null;
        ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();

        URL url = new URL("file:/home/classes/");
        MyClassLoader myClassloader = new MyClassLoader(new URL[] { url });

        URL rurl = myClassloader.getResource("ExampleObjectImpl.class");
        if (rurl != null) {
            System.out.println("rurl:"+rurl.getPath());
        }

        URL[] urls = myClassloader.getURLs();
        for (URL t : urls) {
            System.out.println("urls:"+t.getPath());
        }

        Thread.currentThread().setContextClassLoader(oldClassloader);
        Class<?> cla = Class.forName("javas.system.classloader.ExampleObjectImpl", true,
                oldClassloader);
        Object tempTestObject = cla.newInstance();
        Thread.currentThread().setContextClassLoader(oldClassloader);

        testObject = (ExampleObject) tempTestObject;
        testObject.print("eststestste");

    }

}
